package com.site.wisdom_construction.controller.publicModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.util.HttpRequest;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/21
 * @Description
 */
@Api(tags = "Http请求接口")
@RestController
@RequestMapping("Http")
@CrossOrigin
public class HttpController {

    @ApiOperation(value = "省数据", notes = "")
    @PostMapping("/findProviceData")
    @NoToken
    public OneDataResult findProviceData(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObjectR = new JSONObject();
        HttpRequest httpRequest =new HttpRequest();
        String path = "https://restapi.amap.com/v3/config/district";
                 String aaa = httpRequest.sendGet(path,"key=dcf499ae2a72b7d0485d61bd3818e798");
        oneDataResult.setData(JSONObject.parseObject(aaa));
        return oneDataResult;
    }

    @ApiOperation(value = "省下级数据", notes = "")
    @PostMapping("/findCityData")
    @NoToken
    public OneDataResult findCityData(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObjectR = new JSONObject();
        HttpRequest httpRequest =new HttpRequest();
        String path = "https://restapi.amap.com/v3/config/district";
        String name = (String) map.get("name");
        String aaa = httpRequest.sendGet(path,"key=dcf499ae2a72b7d0485d61bd3818e798&keywords="+name);
        oneDataResult.setData(JSONObject.parseObject(aaa));
        return oneDataResult;
    }
}
